<?php

namespace Home\Controller;
class IndexController extends BaseController
{
    public function index()
    {

        $this->display();
    }

    public function register()
    {
        if (IF_POST) {
            $db_guest = M('guest');
            $data = I('post.');
            $map['mobile'] = $data['mobile'];
            $check = $db_guest->where($map)->find();
            if(empty($check)){
                $data['create_time'] = date("Y-m-d H:i:s", time());
                if ($this->isSend($data['mobile'])) {
                    $data['is_send'] = '1';
                } else {
                    $data['is_send'] = '0';
                }
                $db_guest = M('guest');
                $db_guest->add($data);
                session('guest', $data);
                $this->success('success');
            }else{
                session('guest', $check);
                $this->success('success');
            }

        }
        $this->error('error');
    }

    public function isSend()
    {
//        $sms = new \Org\Util\SendSMS;
//        $result = $sms->sendSMS();
//        dump($result);
        return false;
    }

    public function logout(){
        session(null);
        echo "<script>location.href='".U('Index/index')."'</script>";
    }

    public function login(){
        if(IS_POST){
            $mobile = I('post.mobile');
            $db_guest = M('guest');
            $map['mobile'] = $mobile;
            $data_guest = $db_guest->where($map)->find();
            session('guest',$data_guest);
            $this->success('success');
        }
    }
}